<?php
class ImageLib{
/**
	 * 图片过滤器
	 * @param object $info
	 */
	public function filtPhoto($photo)
	{
		if (! $photo ['name'])
		{
			return "请选择你要上传的图片";
		}
		if (! ($photo ["type"] != "image/gif" || $photo ["type"] == "image/jpeg" || $photo ["type"] == "image/pjpeg"))
		{
			return "图片类型错误";
		}
		if ($photo ["size"] > 100000)
		{
			return "图片大小太大";
		}
		//控制允许上传的图片类型,最后的100000为允许的图片大小
		if ($photo ["error"] > 0)
		{
			return "图片格式错误";
		}
		return TRUE;
	}
	/**
	 * 图片处理
	 * 把图片放到服务器上面，返回图片的路径
	 * @param $_file $photo
	 * @param 要存放的目录 $dir
	 * @param 图片要重命名的名字 $name
	 * 
	 */
	public function addPhoto($photo, $dir, $name)
	{
		
		$photoType = explode ( ".", $photo ["name"] );
		$photoName = $name . "." . $photoType [1];
		$filePath ="myimages/upload/" . $dir . "/" . date ('Y') . "/".date ('m') . "/";
		if (! file_exists ( ROOT_PATH ."/myimages/upload/" . $dir . "/" . date ('Y') . "/".date ('m') . "/"))
		{
			mkdir ( ROOT_PATH ."/myimages/upload/" . $dir . "/" . date ('Y') . "/".date ('m') . "/", 0777 ,TRUE);
		}
		move_uploaded_file ( $photo ["tmp_name"], ROOT_PATH . $filePath . $photoName );
		return WEB_ROOT.$filePath . $photoName;
	}



}